package Day11.试题程序;

import java.util.Scanner;

/**
 * @author HYHwtx
 * @version 1.0
 * @date 2022/2/17 15:28
 */
/*
* 求一个3*3矩阵对角线元素之和*/
public class Test05 {
    public static void main(String[] args) {
        int sum = 0;//取和
        Scanner in = new Scanner(System.in);
        System.out.println("请输入矩阵元素：");
        int[][] array = new int[3][3];
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j <array.length; j++) {
                array[i][j] = in.nextInt();
                if (i==j){
                    sum+= array[i][j];
                }
                if ((i == 0 && j ==2) || (i == 2 && j == 0)){
                    sum+= array[i][j];
                }
            }
            System.out.println(sum);
        }
    }
}
